package com.netx.generics.translation;
import com.netx.generics.basic.Checker;


public abstract class TranslationStep {

	private TranslationStep _nextStep;
	private final TranslationStep _previousStep;
	
	protected TranslationStep(TranslationStep previousStep) {
		Checker.checkNull(previousStep, "previousStep");
		_nextStep = null;
		_previousStep = previousStep;
		_previousStep.setNextStep(this);
	}
	
	// for FirstStep:
	TranslationStep() {
		_nextStep = null;
		_previousStep = null;
	}

	public abstract Object performWork(Results r);
	
	protected void addError(Results r, String where, String message) {
		Checker.checkNull(r, "r");
		Checker.checkEmpty(where, "where");
		Checker.checkEmpty(message, "message");
		r.addError("in '"+where+"': "+message);
	}

	protected void addWarning(Results r, String where, String message) {
		Checker.checkNull(r, "r");
		Checker.checkEmpty(where, "where");
		Checker.checkEmpty(message, "message");
		r.addWarning("in '"+where+"': "+message);
	}

	// for FirstStep.StepIterator:
	TranslationStep getNextStep() {
		return _nextStep;
	}

	// for FirstStep.StepIterator:
	void setNextStep(TranslationStep step) {
		_nextStep = step;
	}
}
